﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.huigo.Framework.ServiceUtils;
using System.Configuration;

namespace com.huigo.B2B.Web.center.account
{
    public partial class Supplement : BasePage, ITransfer
    {
        private PayInfo payInfo = new PayInfo();
        public decimal AlipayRate
        {
            get
            {
                return Convert.ToDecimal(ConfigurationManager.AppSettings["AlipayRate"]);
            }
        }
        public decimal amount
        {
            get
            {
                return RequestDecimal("amount");
            }
        }
        public decimal money
        {
            get
            {
                return RequestDecimal("tbPayPrice");
            }
        }
        private string PayType
        {
            get { return string.IsNullOrEmpty(RequestString("paytype")) ? string.Empty : RequestString("paytype"); }
        }
        decimal PayPrice = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            GetPayPrice();
            if (!string.IsNullOrEmpty(PayType))
            {
                PayIt();
            }
        }
        public string GetUserFee()
        {
            List<RequestFuncParams> list = new List<RequestFuncParams>();
            list.Add(new RequestFuncParams("custId", CustId.ToString()));
            BaseService service = new BaseService();
            ParserXml parser = service.RequestEntryService(Dict.ERequestFunc.GET_CUST_USEFUL_FEE, list);
            if (parser != null && parser.RowsCount > 0)
            {
                return Convert.ToDecimal(parser["CustUsefulFee", 0]).ToString("0.00");
            }
            else
            {
                return "0";
            }
        }
        public string GetAlipayTotalPayPrice()
        {
            decimal AlipayTotalPayPrice = ConvertCurrencyPay(100 / (1 - AlipayRate));
            return AlipayTotalPayPrice.ToString();
        }
        private void GetPayPrice()
        {
            if (amount == 0)
            {
                PayPrice = money;
            }
            else
            {
                PayPrice = amount;
            }
        }
        private void PayIt()
        {
            payInfo.Fee = PayPrice;
            payInfo.CustId = CustId;
            payInfo.PayFor = (int)Dict.PayFor.SUPPLEMENT;

            switch (PayType.ToLower())
            {
                case "alipay":
                    payInfo.PayType = Dict.PayType.ALIPAY.ToString();
                    payInfo.TotalFee = ConvertCurrencyPay(PayPrice / (1 - AlipayRate));
                    TransPayInfo = payInfo;
                    Server.Transfer("~/pay/alipay/Redirect.aspx");
                    break;
            }
        }
        #region ITransfer Members

        public PayInfo TransPayInfo
        {
            get;
            set;
        }

        #endregion

    }
}
